package com.xydtech.ecard.merchant.service.impl;

import com.xydtech.common.annotation.DataScope;
import com.xydtech.common.core.domain.entity.SysDictData;
import com.xydtech.ecard.merchant.domain.EcardCustManagerMerchantPrd;
import com.xydtech.ecard.merchant.mapper.EcardCustManagerMerchantPrdMapper;
import com.xydtech.ecard.merchant.service.IEcardCustManagerMerchantPrdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/*
 * 网点营销商户产品信息统计Service
 *@author lin
 *@version 1.0
 *@create 2023/8/3 9:00
 */
@Service
public class EcardCustManagerMerchantPrdServiceImpl implements IEcardCustManagerMerchantPrdService {

    @Autowired
    private EcardCustManagerMerchantPrdMapper ecardCustManagerMerchantPrdMapper;
    /**
     * 网点建档商户信息统计
     * @param ecardCustManagerMerchantPrd
     * @return
     */
    @Override
    @DataScope(deptAlias = "aa")
    public List<LinkedHashMap<String, Object>> selectCustManagerMerchantPrdInfo(EcardCustManagerMerchantPrd ecardCustManagerMerchantPrd, List<SysDictData> sysDictDataList) {
        //改为根据字典展示对应字段
        List<LinkedHashMap<String, Object>> ecardCustManagerMerchantPrds = ecardCustManagerMerchantPrdMapper.selectCustManagerMerchantPrdInfo(ecardCustManagerMerchantPrd);
        for (Map<String, Object> merchantPrdMap : ecardCustManagerMerchantPrds) {
            String userId = String.valueOf(merchantPrdMap.remove("user_id"));
            merchantPrdMap.remove("dept_id");
            String deptName = String.valueOf(merchantPrdMap.remove("dept_name"));
            String userName = String.valueOf(merchantPrdMap.remove("user_name"));
            merchantPrdMap.put("机构名称", deptName);
            merchantPrdMap.put("营销人员", userName);
            for (SysDictData sysDictData : sysDictDataList) {
                String dictValue = sysDictData.getDictValue();
                Integer nums = ecardCustManagerMerchantPrdMapper.selectMerchantPrdByBusinessLabel(dictValue, userId);
                if (nums == null){
                    nums = 0;
                }
                merchantPrdMap.put(sysDictData.getDictLabel(),nums);
            }
        }
        return ecardCustManagerMerchantPrds;
    }

    /**
     * 客户经理营销企业产品信息统计
     * @param ecardCustManagerMerchantPrd
     * @param sysDictDataList
     * @return
     */
    @Override
    @DataScope(deptAlias = "aa")
    public List<LinkedHashMap<String, Object>> selectCustManagerEnterprisePrdInfo(EcardCustManagerMerchantPrd ecardCustManagerMerchantPrd, List<SysDictData> sysDictDataList) {
        //改为根据字典展示对应字段
        List<LinkedHashMap<String, Object>> ecardCustManagerMerchantPrds = ecardCustManagerMerchantPrdMapper.selectCustManagerEnterprisePrdInfo(ecardCustManagerMerchantPrd);
        for (Map<String, Object> merchantPrdMap : ecardCustManagerMerchantPrds) {
            String userId = String.valueOf(merchantPrdMap.remove("user_id"));
            merchantPrdMap.remove("dept_id");
            String deptName = String.valueOf(merchantPrdMap.remove("dept_name"));
            String userName = String.valueOf(merchantPrdMap.remove("user_name"));
            merchantPrdMap.put("机构名称", deptName);
            merchantPrdMap.put("营销人员", userName);
            for (SysDictData sysDictData : sysDictDataList) {
                String dictValue = sysDictData.getDictValue();
                Integer nums = ecardCustManagerMerchantPrdMapper.selectEnterprisePrdByBusinessLabel(dictValue, userId);
                if (nums == null){
                    nums = 0;
                }
                merchantPrdMap.put(sysDictData.getDictLabel(),nums);
            }
        }
        return ecardCustManagerMerchantPrds;
    }

    /**
     * 客户经理营销农业产品信息统计
     * @param ecardCustManagerMerchantPrd
     * @param sysDictDataList
     * @return
     */
    @Override
    @DataScope(deptAlias = "aa")
    public List<LinkedHashMap<String, Object>> selectCustManagerAgriculturePrdInfo(EcardCustManagerMerchantPrd ecardCustManagerMerchantPrd, List<SysDictData> sysDictDataList) {
        //改为根据字典展示对应字段
        List<LinkedHashMap<String, Object>> ecardCustManagerMerchantPrds = ecardCustManagerMerchantPrdMapper.selectCustManagerAgriculturePrdInfo(ecardCustManagerMerchantPrd);
        for (Map<String, Object> merchantPrdMap : ecardCustManagerMerchantPrds) {
            String userId = String.valueOf(merchantPrdMap.remove("user_id"));
            merchantPrdMap.remove("dept_id");
            String deptName = String.valueOf(merchantPrdMap.remove("dept_name"));
            String userName = String.valueOf(merchantPrdMap.remove("user_name"));
            merchantPrdMap.put("机构名称", deptName);
            merchantPrdMap.put("营销人员", userName);
            for (SysDictData sysDictData : sysDictDataList) {
                String dictValue = sysDictData.getDictValue();
                Integer nums = ecardCustManagerMerchantPrdMapper.selectAgriculturePrdByBusinessLabel(dictValue, userId);
                if (nums == null){
                    nums = 0;
                }
                merchantPrdMap.put(sysDictData.getDictLabel(),nums);
            }
        }
        return ecardCustManagerMerchantPrds;
    }

    /**
     * 客户经理营销个人产品信息统计
     * @param ecardCustManagerMerchantPrd
     * @param sysDictDataList
     * @return
     */
    @Override
    @DataScope(deptAlias = "aa")
    public List<LinkedHashMap<String, Object>> selectCustManagerPersonPrdInfo(EcardCustManagerMerchantPrd ecardCustManagerMerchantPrd, List<SysDictData> sysDictDataList) {
        //改为根据字典展示对应字段
        List<LinkedHashMap<String, Object>> ecardCustManagerMerchantPrds = ecardCustManagerMerchantPrdMapper.selectCustManagerPersonPrdInfo(ecardCustManagerMerchantPrd);
        for (Map<String, Object> merchantPrdMap : ecardCustManagerMerchantPrds) {
            String userId = String.valueOf(merchantPrdMap.remove("user_id"));
            merchantPrdMap.remove("dept_id");
            String deptName = String.valueOf(merchantPrdMap.remove("dept_name"));
            String userName = String.valueOf(merchantPrdMap.remove("user_name"));
            merchantPrdMap.put("机构名称", deptName);
            merchantPrdMap.put("营销人员", userName);
            for (SysDictData sysDictData : sysDictDataList) {
                String dictValue = sysDictData.getDictValue();
                Integer nums = ecardCustManagerMerchantPrdMapper.selectPersonPrdByBusinessLabel(dictValue, userId);
                if (nums == null){
                    nums = 0;
                }
                merchantPrdMap.put(sysDictData.getDictLabel(),nums);
            }
        }
        return ecardCustManagerMerchantPrds;
    }

}
